$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/flowTask/list',
        datatype: "json",
        colModel: [
            {label: '提现id', name: 'takeId', index: "activeId", width: 45, key: true, sortable: false, align: 'center'},
            {label: '提现时间', name: 'createTime', width: 75, sortable: false, align: 'center'},
            {
                label: '提现金额',
                name: 'takeAmount',
                width: 60,
                sortable: false,
                formatter: function (value, options, row) {
                    return value.toFixed(2);
                },
                align: 'center'
            },
            {
                label: '手续费',
                name: 'serviceAmount',
                width: 45,
                sortable: false,
                formatter: function (value, options, row) {
                    return value.toFixed(2);
                },
                align: 'center'
            },
            {
                label: '实际到款',
                name: 'actAccountAmount',
                width: 75,
                sortable: false,
                formatter: function (value, options, row) {
                    return value.toFixed(2);
                },
                align: 'center'
            },
            {label: '结果明细', name: 'explains', width: 120, sortable: false, align: 'center'},

            {label: '提现方式', name: 'takeType', width: 60, sortable: false, align: 'center'},
            {label: '提现人姓名', name: 'name', width: 75, sortable: false, align: 'center'},
            {label: '提现人手机号码', name: 'phone', width: 75, sortable: false, align: 'center'},
            {
                label: '总分润',
                name: 'totalAmount',
                width: 55,
                sortable: false,
                formatter: function (value, options, row) {
                    return value.toFixed(2);
                },
                align: 'center'
            },
            {
                label: '当前余额',
                name: 'availableAmount',
                width: 55,
                sortable: false,
                formatter: function (value, options, row) {
                    return value.toFixed(2);
                },
                align: 'center'
            },
            {
                label: '实时余额',
                name: 'currentAmount',
                width: 55,
                sortable: false,
                formatter: function (value, options, row) {
                    return value.toFixed(2);
                },
                align: 'center'
            },
            {
                label: '实时提后余额',
                name: 'afterAmount',
                width: 55,
                sortable: false,
                formatter: function (value, options, row) {
                    return value.toFixed(2);
                },
                align: 'center'
            }
        ],
        viewrecords: true,
        height: "auto",
        rowNum: 10,
        rowList: [10, 30, 50],
        rownumbers: true,
        caption: "提现列表",
        rownumWidth: 25,
        autowidth: true,
        multiselect: true,
        multiboxonly: true,
        pager: "#jqGridPager",
        jsonReader: {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        loadComplete: function () {
            vm.refresh();
        },
        gridComplete: function () {

            //隐藏grid底部滚动条
            //$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
            $('#jqGrid').closest("div.ui-jqgrid-view")
                .children("div.ui-jqgrid-titlebar")
                .css("text-align", "center")
                .children("span.ui-jqgrid-title")
                .css("float", "none");
        }
    });
    countFlowTake();
});


var vm = new Vue({
    el: '#rrapp',
    data: {
        q: {
            startTime: null,
            endTime: null,
            name: null,
            phone: null,
            takeState: ""
        },
        showList: true,
        showAdd: false,
        addById: false,
        title: null,
        takeStates: [{
            value: "",
            msg: "请选择提现状态"
        }, {
            value: "SUCCESS",
            msg: "提现成功"
        }, {
            value: "FAILURE",
            msg: "提现失败"
        }, {
            value: "EXAMINE",
            msg: "审核中"
        }, {
            value: "WAIT",
            msg: "提现挂起"
        }
        ]
    },
    methods: {
        query: function () {
            vm.reload();
        },
        clean: function () {
            vm.showList = true;
            vm.q = {
                startTime: null,
                endTime: null,
                explains: null,
                name: null,
                phone: null,
                takeState: ""
            };
            $("#startTime").val(null);
            $("#endTime").val(null);
            $("#jqGrid").jqGrid('setGridParam', {page: 1});
            vm.reload();
        },

        reload: function () {
            vm.showList = true;
            vm.showAdd = false;
            vm.statistics();
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {
                    'startTime': vm.q.startTime,
                    'endTime': vm.q.endTime,
                    'explains': vm.q.explains,
                    "name": vm.q.name,
                    'phone': vm.q.phone,
                    'takeState': vm.q.takeState
                },
                page: page
            }).trigger("reloadGrid");
            $("#totalGrid").jqGrid('setGridParam', {
                postData: {
                    'startTime': vm.q.startTime,
                    'endTime': vm.q.endTime,
                    'explains': vm.q.explains,
                    "name": vm.q.name,
                    'phone': vm.q.phone,
                    'takeState': vm.q.takeState
                },
                page: page
            }).trigger("reloadGrid");
        },
        //统计提现
        statistics: function () {
            countFlowTake();
        },
        refresh: function () {
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#totalGrid").jqGrid('setGridParam', {
                postData: {
                    'startTime': vm.q.startTime,
                    'endTime': vm.q.endTime,
                    'explains': vm.q.explains,
                    "name": vm.q.name,
                    'phone': vm.q.phone,
                    'takeState': vm.q.takeState
                },
                page: page
            }).trigger("reloadGrid");
        },
        commitTakeList: function () {

            let rows = getSelectedRows();
            if (rows == null) {
                return;
            }
            let index;
            $.ajax({
                type: "POST",
                url: baseURL + "sys/flowTask/commitTake",
                contentType: "application/json",
                data: JSON.stringify(rows),
                beforeSend: function () {
                    index = layer.load(2, {
                        shade: [0.8, '#fff']
                    });
                },
                complete: function () {
                    layer.close(index);
                },
                success: function (r) {
                    alert(r.msg, function () {
                        vm.reload();
                    })
                }
            });
        }, down: function () {
            window.location.href = baseURL + "sys/flowTask/downLoad";
        }

    }
});

function countFlowTake() {
    $("#totalGrid").jqGrid({
        url: baseURL + 'sys/flowTask/countFlowTake',
        datatype: "json",
        colModel: [
            {
                label: '当前条件提现总计',
                name: 'currTakeSum',
                width: 45,
                sortable: false,
                align: 'center',
                cellattr: addCellAttr,
                formatter: function (value, options, row) {
                    return value;
                }
            },
            {
                label: '当前条件实际到款总计',
                name: 'realAmount',
                width: 75,
                sortable: false,
                align: 'center',
                cellattr: addCellAttr
            },
            {
                label: '当月提现总计',
                name: 'totalTakeCurMon',
                width: 45,
                sortable: false,
                align: 'center',
                cellattr: addCellAttr,
                formatter: function (value, options, row) {
                    return value.toFixed(2);
                }
            },
            {
                label: '本周提现总计',
                name: 'totalTakeCurWeek',
                width: 75,
                sortable: false,
                align: 'center',
                cellattr: addCellAttr,
                formatter: function (value, options, row) {
                    return value.toFixed(2);
                }
            },
            {
                label: '昨日提现总计',
                name: 'totalTakeCurYesterday',
                width: 75,
                sortable: false,
                align: 'center',
                cellattr: addCellAttr,
                formatter: function (value, options, row) {
                    return value.toFixed(2);
                }
            },
            {
                label: '所有合伙人收入总计',
                name: 'takeSum.allAmount',
                width: 75,
                sortable: false,
                align: 'center',
                cellattr: addCellAttr,
                formatter: function (value, options, row) {
                    return value.toFixed(2);
                }
            },
            {
                label: '所有合伙人可提现总计',
                name: 'takeSum.availableAmount',
                width: 75,
                sortable: false,
                align: 'center',
                cellattr: addCellAttr,
                formatter: function (value, options, row) {
                    return value.toFixed(2);
                }
            },


        ],
        viewrecords: true,
        height: "auto",
        rowNum: 10,
        rowList: [10, 30, 50],
        rownumbers: false,
        caption: "提现统计",
        rownumWidth: 25,
        autowidth: true,
        jsonReader: {
            root: "page",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        pager: "#totalGridPager",
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },

        gridComplete: function () {
            //隐藏grid底部滚动条
            $("#totalGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
            //隐藏分页条件
            $("#totalGridPager").hide();
            $('#totalGrid').closest("div.ui-jqgrid-view").children("div.ui-jqgrid-titlebar")
                .css("text-align", "center")
                .children("span.ui-jqgrid-title")
                .css("float", "none");

        }
    });
}

//文字染色
function addCellAttr() {
    return "style='color:#2619FF'";
}